<template>
    <div class="home-singer">
        <h3>热门歌手</h3>
        <div class="wrapper" ref="wrapper">
            <ul class="content">
                <li v-for="(item, index) in listData" :key="index" @click="selectItem(item)">
                    <div class="cover">
                        <van-image :src="item.picUrl" style="width:150px;height:122px"></van-image>
                    </div>
                    <span>{{ item.name }}</span>
                </li>
            </ul>
        </div>
    </div>
</template>
  
<script>
//import axios from 'axios'
import BScroll from 'better-scroll'
export default {
    data() {
        return {
            listData: []
        }
    },
    created() {
        this.getSingerListData()
    },
    methods: {
        getSingerListData() {
            this.$request('get', '/toplist/artist')
                // this.$request('get', '/recommend/playlist/u')
                .then(code => {
                    console.log(code)
                    this.listData = code.list.artists
                    // this.listData = result.data.list
                    console.log(this.listData)
                    this.$nextTick(() => {
                        this.scroll = new BScroll(this.$refs.wrapper, {
                            scrollY: false,
                            scrollX: true,
                            startX: 0,
                            click: true,
                        })
                    })
                })
        },
        //列表项的点击事件
        selectItem(item) {
            const singermid = item.id;//歌手的id
            //1调用状态管理，commit提交唤醒mutations
            // this.$store.commit('saveSinger', item)
            //2调用状态管理，通过分发action方法，通过dispatch
            this.$store.dispatch("saveSinger", item)
            this.$router.push(`/singer/${singermid}`);
        }
    },
}
</script>
      
<style scoped>
/* .home-recommond > ul {
    display: flex;
    flex-wrap: wrap;
  }
  .home-recommond > ul > li {
    width: calc((100% - 1rem) / 3 * 1);
  }
  .home-recommond > ul > li:nth-of-type(3n + 2) {
    margin-left: 0.5rem;
    margin-right: 0.5rem;
  } */
.cover {
    position: relative;
}

.wrapper {
    width: 100%;
    /* 容器的宽度就是屏幕的宽度 */
    overflow: hidden;
}

/* content内容区的宽度要大于wrapper容器的宽度，12个列表项 */
ul.content {
    width: calc(100 * 10rem);
    /* width: calc(12 * 10rem); */
}

ul.content li {
    /**li默认是块级元素，修改为行内元素，但是要具备块级元素的特性*/
    display: inline-block;
    width: 10rem;
    vertical-align: top;
}

ul.content li * {
    margin: 0 0.1rem;
    /*里面的元素与li的边缘有个间距*/
}


ul.content>li>span {
    font-size: 0.8rem;
    color: #625858;
}
</style>